<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>生成</title>
<LINK href="style/css/ui-lightness/jquery-ui-1.8.8.custom.css" type=text/css rel=stylesheet>
<SCRIPT src="style/js/jquery-1.4.2.min.js" type=text/javascript></SCRIPT>
<SCRIPT src="style/js/jquery-ui-1.8.6.custom.min.js" type=text/javascript></SCRIPT>
</head>

<body>
<style>
.ui-progressbar-value { background-image: url(/style/css/ui-lightness/images/pbar-ani.gif); background-repeat:repeat }
.sp {float:right; padding-right:20px; color:green;}
</style>

<div class="demo" align="center" style="width:60%;">
	<div id="progressbar" style="height:12px;"></div>
    <div class="demo-description">
        <p>
        <code>
        进度：<code id="start">0</code>/<code id="end"><%$nums%></code>
        耗时：<code id="time">0</code>秒
        平均: <code id="pj">0</code>
        预计剩余: <code id="yj">0</code>秒
        <code id="close" style="display:none; color:green;">所有页面生成完成 <a href="javascript:window.close();">关闭页面</a></code>
        </code>
        </p>
	</div><!-- End demo-description -->
    <code><div class="list" align="left"></div></code>
</div><!-- End demo -->
<script>
action		= <%$action%>;
action		= eval(action);
nums		= <%$nums%>;
wid			= <%$wid%>;
start		= 0;
made		= 0;
cKey		= 0;
bKey		= 0;
pKey		= 0;
classid		= <%$classid%>;
var date	= new Date;
startT		= date.getTime();
$(function() {
	$( "#progressbar" ).progressbar({value: 0});
	toMake();
});

function toMake()
{
	if (action[start] == 'index') makeIndex();
	if (action[start] == 'column') makeColumn();
	if (action[start] == 'page') makePage();
}
function makeIndex(){
	$.getJSON('index.php?m=system&a=toMake',{'action':action[start],'wid':wid},function(data){
		showMessage(data);
		start++;
		toMake();
	});
}
function makeColumn(){
	if (cKey >= classid.length){
		start++;
		toMake();
	}
	else {
		var cid = new Array;
		for(i=0;i<10;i++){
			cid[i]	= classid[cKey];
			cKey++;	
		}
		$.getJSON('index.php?m=system&a=toMake',{'action':action[start],'wid':wid,'classid':cid},function(data){
			showMessage(data);
			makeColumn();
		});
	}
}
function makePage(){
	if (pKey >= classid.length){
		start++;
		toMake();
	}
	else {
		$.getJSON('index.php?m=system&a=toMake&id=classid',{'action':action[start],'wid':wid,'classid':classid[pKey]},function(data){
			showMessage(data);
			pKey++;	
			makePage();
		});
	}	
}

function showMessage(data)
{
	made	= made + data.made;
	$("#start").html(made);
	$( "#progressbar" ).progressbar({value: made/nums*100});
	$(data.url).each(function(key,value){
		var s	= '';
		if (bKey%2 == 0) s='background:#F3F8F7;'; 
		$(".list").append('<div style="height:20px;'+s+'"><a href="'+data.url[key]+'" target="_blank" style="float:left;">'+data.title[key]+'</a><span class="sp"> &raquo; 生成完成</span></div>');
		bKey++;
	});
	
	var date	= new Date;
	var endT	= date.getTime();
	var	t		= (endT-startT)/1000;
	
	$("#time").html(t.toFixed(2));
	$("#pj").html((t/made).toFixed(2));
	$("#yj").html(((t/made)*(nums-made)).toFixed(2));
	
	if (made >= nums) document.getElementById("close").style.display = '';
}
</script>

</body>
</html>
